<template>
  <div v-html="content"></div>
</template>

<script>
import { doGet } from "@/helper/ajax_helper.js";
import cheerio from "cheerio";
export default {
  data() {
    return {
      content:"",
      regFilmid: /filmId:'(\d+)'/g,
      regUrl: /url:'(.*)'/g,
    }
  },
  name: "Findinfos",
  components: {},
  methods: {
    handleContent(html) {
      // 通过$对象
       let newHtml ="";
      const $ = cheerio.load(html);
     $("a").each(
       (index,el)=>{
         let newHref =null;
         const href =$(el).prop("href");
        
          console.log("href===",$(el).prop("href"));
         if(this.regFilmid.test(href)){
           console.log("testregfilmid111111===",this.regFilmid.test(href));
          // arr.push(`/Films/${this.regFilmid.exec(href)[1]}`);
          newHref =`#/Detail/${this.regFilmid.exec(href)[1]}`;
         }
         else if(this.regUrl.test(href)){
           console.log("regurltest===",this.regUrl.test(href));
          //  arr.push(arr.push(`/Films/${this.regUrl.exec(href)[1]}`));
          newHref =`${this.regUrl.exec(href)[1]}`;
         }
         else{
          //  arr.push("#")
          newHref ="#";
         }
         $(el).prop("href",newHref);
         newHtml +=$(el).toString();
       }
     )
     return newHtml;
    },
  },
  mounted() {
    doGet(
      "https://m.maizuo.com/gateway?actId=ElzMZU125260",
      "mall.act.static-page.info",
      (res) => {
       this.content=this.handleContent(res.data.data.content)
      }
    );
  },
};
</script>
